package org.qqcui.designpattern.patterns.chain;

/**
 * 责任链模式客户端
 *
 * @author cuiqingqiang
 * @version 1.0
 * @date 2022/5/7 17:10
 **/
public class Client {
    public static void main(String[] args) {
        PurchaseRequest request = new PurchaseRequest(1, 300000, 1);

        DepartmentApprover departmentApprover = new DepartmentApprover("李主任");
        CollegeApprover collegeApprover = new CollegeApprover("张院长");
        ViceSchoolMasterApprover viceSchoolMasterApprover = new ViceSchoolMasterApprover("赵副校长");
        SchoolMasterApprover schoolMasterApprover = new SchoolMasterApprover("王校长");

        // 设置审批链，是一个环，防止报空指针
        departmentApprover.setNextApprover(collegeApprover);
        collegeApprover.setNextApprover(viceSchoolMasterApprover);
        viceSchoolMasterApprover.setNextApprover(schoolMasterApprover);
        schoolMasterApprover.setNextApprover(departmentApprover);

        // 开始审批流程
        departmentApprover.processRequest(request);
    }
}
